package com.wu.client.controller;

import com.wu.client.service.FollowersService;
import com.wu.client.service.SongService;
import com.wu.client.service.UserService;
import com.wu.client.vo.req.user.UserFollowReq;
import com.wu.client.vo.req.user.UserLoginReq;
import com.wu.client.vo.req.user.UserRegisterReq;
import com.wu.client.vo.res.PageResp;
import com.wu.client.vo.res.community.PostResp;
import com.wu.client.vo.res.user.UserFollowingResp;
import com.wu.client.vo.res.user.UserLoginResp;
import com.wu.client.vo.res.user.UserProfile;
import com.wu.client.vo.res.user.UserStats;
import com.wu.client.vo.res.playlist.PlaylistBaseResp;
import com.wu.common.convertion.result.Result;
import com.wu.common.convertion.result.Results;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Cousin
 * @date 2025/3/6
 * @Description
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/user")
public class UserController {
    private final FollowersService followersService;
    private final UserService userService;

    @PostMapping("/register")
    public Result<Boolean> register(@RequestBody UserRegisterReq userRegisterReq) {
        // 注册新用户
        userService.register(userRegisterReq);
        return Results.success(true);
    }
    @PostMapping("/login")
    public Result<UserLoginResp> login(@RequestBody UserLoginReq userLoginReq) {
        return Results.success(userService.login(userLoginReq));
    }
    @GetMapping("/profile/{userId}")
    public Result<UserProfile> getProfile(@PathVariable Long userId) {
        UserProfile user =new UserProfile();
        user.setUsername("cousin");
        user.setAvatar("/img/avatar/1.jpg");
        user.setId(1L);
        user.setBio("今天天气很好");
        user.setCover("/img/cover/1.jpg");
        UserStats userStats = new UserStats();
        userStats.setAlbumsCount(10);
        userStats.setSongsCount(20);
        userStats.setFollowingCount(10);
        userStats.setFollowersCount(5);
        userStats.setMvsCount(5);
        userStats.setPlaylistsCount(20);
        user.setStats(userStats);
        // 获取用户信息
        return Results.success(user);
    }

    @GetMapping("/playlists")
    public Result<List<PlaylistBaseResp>> getUserPlaylists(@RequestParam Long userId, @RequestParam(defaultValue = "50") Integer limit) {
        List<PlaylistBaseResp> playlistRespList = new ArrayList<>();
        // 创建 Playlist 实例
        PlaylistBaseResp playlist = new PlaylistBaseResp();
        // 使用 setter 方法设置属性
        playlist.setId(1L);
        playlist.setTitle("My Playlist");
        playlist.setCover("/img/cover/3.jpg");
        playlist.setIsLiked(true);
        playlist.setCreatedAt("2025-03-09");
        playlistRespList.add(playlist);
        // 获取用户的歌单
        return Results.success(playlistRespList);
    }
    @GetMapping("/following")
    public Result<PageResp<UserFollowingResp>> getUserFollowing(@RequestParam Long userId, @RequestParam(defaultValue = "50") Integer limit) {
        // 创建 UserFollowing 实例
        List<UserFollowingResp> userFollowings = new ArrayList<>();
        UserFollowingResp userFollowing = new UserFollowingResp();

        // 使用 setter 方法设置属性
        userFollowing.setId("123");
        userFollowing.setUsername("John Doe");
        userFollowing.setAvatar("https://example.com/avatar.jpg");
        //userFollowings.add(userFollowing);
        // 获取用户的关注列表
        PageResp<UserFollowingResp> pageResp = new PageResp<>();
        pageResp.setItems(userFollowings);
        pageResp.setTotal(1L);
        pageResp.setPage(1);
        pageResp.setLimit(50);
        return Results.success(pageResp);

    }
    @GetMapping("/followers")
    public Result<PageResp<UserFollowingResp>> getUserFollowers(@RequestParam Long userId, @RequestParam(defaultValue = "50") Integer limit) {
        // 创建 UserFollowing 实例
        List<UserFollowingResp> userFollowings = new ArrayList<>();
        UserFollowingResp userFollowing = new UserFollowingResp();
        // 使用 setter 方法设置属性
        userFollowing.setId("123");
        userFollowing.setUsername("John Doe");
        userFollowing.setAvatar("img/avatar/2.jpg");
        userFollowings.add(userFollowing);
        PageResp<UserFollowingResp> pageResp = new PageResp<>();
        pageResp.setItems(userFollowings);
        pageResp.setTotal(1L);
        pageResp.setPage(1);
        pageResp.setLimit(50);
        // 获取用户的关注列表
        return Results.success(pageResp);
    }
    @PostMapping("follow")
    public Result<Void> follow(@RequestBody UserFollowReq userFollowReq) {
        followersService.add(userFollowReq);
        return Results.success();
    }
    @DeleteMapping("unfollow")
    public Result<Void> removeUser(@RequestParam Long userId,@RequestParam Long followedId,@RequestParam Integer fansType) {
        followersService.delete(userId,followedId,fansType);
        return Results.success();
    }


}
